package com.tuzhi.convert.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CadFileTypeUtils {
    final static String pattern_xt = ".*\\.x_t?$";
    final static String pattern_prt = ".*\\.prt?$";
    final static String pattern_prt_num = ".*\\.prt\\.\\d+$";
    final static String pattern_zip = ".*\\.zip?$";
    final static String pattern_rar = ".*\\.rar?$";

    public static String getCadFileType(String fileName) {
        Pattern pattern = Pattern.compile(pattern_xt, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        Matcher matcher = pattern.matcher(fileName);
        boolean result = matcher.matches();
        if (result)
            return ".x_t";
        pattern = Pattern.compile(pattern_prt, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        matcher = pattern.matcher(fileName);
        result = matcher.matches();
        if (result)
            return ".prt";
        pattern = Pattern.compile(pattern_prt_num, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        matcher = pattern.matcher(fileName);
        result = matcher.matches();
        if (result)
            return ".prt.1";
        pattern = Pattern.compile(pattern_zip, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        matcher = pattern.matcher(fileName);
        result = matcher.matches();
        if (result)
            return ".zip";
        pattern = Pattern.compile(pattern_rar, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        matcher = pattern.matcher(fileName);
        result = matcher.matches();
        if (result)
            return ".rar";
        return null;
    }

    public static void main(String[] args) {
        System.out.println(getCadFileType("123.x_T"));
        System.out.println(getCadFileType("123.Prt"));
        System.out.println(getCadFileType("123.Prt.12"));
        System.out.println(getCadFileType("123.Zip"));
        System.out.println(getCadFileType("123.rar"));
    }
}
